package com.tool.main;

import com.tool.bean.QBOGenInfo;
import com.tool.util.StringUtil;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class QBOReader
{
  public static Map getParams(QBOGenInfo info)
    throws Exception
  {
    Map result = new HashMap();
    result.put("Bean", info.getBeanName());
    result.put("bean", StringUtil.lowerFirst(info.getBeanName()));
    result.put("package", info.getPackageName());
    result.put("SELECT_SQL", info.getSelectSql().toUpperCase());
    if (StringUtil.isEmptyString(info.getSelectSql()))
    {
      result.put("COUNT_SQL", new StringBuilder("SELECT COUNT(*) FROM (").append(info.getSelectSql()).toString().toUpperCase() + ") AS T_ ");
    }
    else
    {
      result.put("COUNT_SQL", info.getCountSql().toUpperCase());
    }

    List fields = new ArrayList();
    List list = info.getFields();
    for (int i = 0; i < list.size(); i++)
    {
      String[] tmps = ((String)list.get(i)).split(",");
      String colName = tmps[0];
      String javaName = tmps[2];
      String javaType = tmps[3];
      Map field = new HashMap();

      field.put("name", javaName);
      field.put("Name", StringUtil.getBeanName(colName));
      field.put("col", colName);
      field.put("javaType", javaType);
      fields.add(field);
    }
    result.put("fields", fields);

    System.out.println("Load Config Success");
    return result;
  }
}